package com.juhuixing.common.assembly.trans;

import com.juhuixing.common.feign.FeignSpringFormEncoder;
import feign.Request;
import feign.Retryer;
import feign.codec.Encoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import java.util.concurrent.TimeUnit;

/**
 * @author: 刘猛
 * @date: 2019/5/5 15:07
 **/
@Configuration
public class TransConfiguration {

    @Bean
    public Retryer feignRetryer() {
        return new Retryer.Default(100L, TimeUnit.SECONDS.toMillis(1L), 0);
    }

    @Bean
    Request.Options requestOptions(ConfigurableEnvironment env){
        int ribbonReadTimeout = env.getProperty("ribbon.ReadTimeout", int.class, 60000);
        int ribbonConnectionTimeout = env.getProperty("ribbon.ConnectTimeout", int.class, 30000);

        return new Request.Options(ribbonConnectionTimeout, ribbonReadTimeout);
    }

    /**支持微服务之间文件上传（已支持多文件上传）**/
    @Bean
    public Encoder feignFormEncoder() {
        return new FeignSpringFormEncoder();
    }

    @Bean
    public feign.Logger.Level multipartLoggerLevel() {
        return feign.Logger.Level.FULL;
    }
}
